import {message} from 'antd';
import {formatMessage} from './intl';
export const hasPermissions = (data, name) => Array.isArray(data) && data.length > 0 && data.some(item => item === name);

export const createValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.brandId)
        emptyErrors.push(formatMessage({
            id: 'utils.empty.brand',
            defaultMessage: '品牌'
        }));
    // if(!data || !data.secomdClaimPeriodId)
    //     emptyErrors.push(formatMessage({
    //         id: 'utils.empty.secomdClaimPeriodId)',
    //         defaultMessage: '周期'
    //     }));
    if(!data || !data.beginDate)
        emptyErrors.push(formatMessage({
            id: 'utils.empty.beginDate',
            defaultMessage: '开始时间'
        }));
    if(!data || !data.endDate)
        emptyErrors.push(formatMessage({
            id: 'utils.empty.endDate',
            defaultMessage: '结束时间'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'utils.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    if(data.beginDate >= data.endDate) {
        message.warning(formatMessage({
            id: 'utils.empty.beginorendDate',
            defaultMessage: '开始时间不能大于等于结束时间'
        }));
        return false;
    }
    return true;
};
import stringify from 'Shared/utils/stringify';
export const formatPrintUrl = condition => `/afterSales/print/secondClaimSummaryReport.html?${stringify(condition)}
    &name=SecondClaimSummary&title=${encodeURI('供应商汇总表打印')}`;
